const {
  formatTime
} = require('../../../utils/util.js');
const {
  getUserLevel,
  getVipDescribe,
  getUserInfo
} = require('../../../api/api.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    leVel: null,
    vip: "",
    svip: "",
    imgHost: '',
    getUserInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
        imgHost: app.img_host,
      }),
      /**
       * 获取vip等级
       */
      getUserLevel().then(res => {
        console.log(res.level)
        this.setData({
          leVel: res.level
        })
      }).catch(err => {
        console.log(err)
      }),
      /**
       * 获取vip等级介绍图片
       */
      getVipDescribe().then(res => {
        this.setData({
          vip: res.data.vip_describe,
          svip: res.data.svip_describe,
        })
      }).catch(err => {
        console.log(err)
      })
    /* 获取用户基本信息 */
    getUserInfo().then(res => {
      let vip_out_time = res.data.vip_out_time;
      if (vip_out_time) {
        const time = new Date(vip_out_time * 1000);
        vip_out_time = formatTime(time);
      }
      res.data.vip_out_time = vip_out_time;
      this.setData({
        getUserInfo: res.data
      })
    }).catch(err => {
      console.log(err)
    })
  }
})